
package cn.tedu.hospital.admin.server.doctor.servic.impl;


import cn.tedu.hospital.admin.server.core.ex.ServiceException;
import cn.tedu.hospital.admin.server.core.web.ServiceCode;
import cn.tedu.hospital.admin.server.doctor.dao.persist.repository.IDoctorRepository;
import cn.tedu.hospital.admin.server.doctor.pojo.entity.Doctor;
import cn.tedu.hospital.admin.server.doctor.pojo.param.DoctorTypeAddNewParam;
import cn.tedu.hospital.admin.server.doctor.servic.IDoctorService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class DoctorServiceImpl implements IDoctorService {
    @Autowired
    private IDoctorRepository doctorRepository;
    public DoctorServiceImpl() {
        log.info("创建业务对象：DoctorServiceImpl");
    }

    @Override
    public void addNew(DoctorTypeAddNewParam doctorTypeAddNewParam) {
        log.debug("开始处理【新增标签类别】的业务，参数：{}", doctorTypeAddNewParam);

        String name = doctorTypeAddNewParam.getName();
        int count = doctorRepository.countByName(name);
        if (count > 0) {
            String message = "新增名称失败，标签类别名称已经被占用！";
            log.warn(message);
            throw new ServiceException(ServiceCode.ERROR_CONFLICT, message);
        }

        Doctor doctor = new Doctor();
        BeanUtils.copyProperties(doctorTypeAddNewParam, doctor);
        doctor.setId(0L);
        doctorRepository.insert(doctor);

    }
}